#!/bin/sh
# flac plugin for CueSplitter
# Nov. 2008 by Nathan Fisher

# Where are we?
PLUGINDIR="$APPDIR/plugins/flac"

# Get translations
ENVIRONMENT_LANG=`echo $LANG | sed "s/\(..\).*/\1/"` #detect environment language 
case $ENVIRONMENT_LANG in
	de)	export LANGUAGE="german" ;;
	en)	export LANGUAGE="english" ;;
	es)	export LANGUAGE="spanish" ;;
	fr)	export LANGUAGE="french" ;;
	it)	export LANGUAGE="italian" ;;
	nb)	export LANGUAGE="norwegian" ;; #translation is norwegian bokmål
	nl)	export LANGUAGE="dutch" ;;
	nn)	export LANGUAGE="norwegian" ;; #Use norwegian bokmål, since there is no norwegian nynorsk
	ru)	export LANGUAGE="russian" ;;
	*)	export LANGUAGE="english" ;; #english for contries without translation
esac
. $PLUGINDIR/locale/english.po #always run to fill gaps in translation
[ -f "$PLUGINDIR/locale/${LANGUAGE}.po" ] && . $PLUGINDIR/locale/${LANGUAGE}.po 2> /dev/null

# set the file extension
export EXT="flac"

# Setup working space for plugin
[ ! -d "$HOME/.config/cuesplitter/plugins/flac" ] && mkdir "$HOME/.config/cuesplitter/plugins/flac"

# Plugin preferences
[ -f "$HOME/.config/cuesplitter/plugins/flac/preferences" ] && . "$HOME/.config/cuesplitter/plugins/flac/preferences"

plugin_options() {
 COMPLEVELS="<item>$COMP</item>"
 for NUM in 0 1 2 3 4 5 6 7 8
 do
  COMPLEVELS="$COMPLEVELS<item>$NUM</item>"
 done
 
 export OPTS_DLG="
 <window title=\"$LOC_FLAC_OPTS\" icon_name=\"audio-x-generic\">
  <vbox>
   <frame $LOC_COMP_LEVEL>
    <hbox>
     <text>
      <label>$LOC_COMP_LEGEND</label>
     </text>
     <combobox>
      $COMPLEVELS
      <variable>COMP</variable>
     </combobox>
    </hbox>
   </frame>
   <hbox>
    <button>
     <input file stock=\"gtk-close\"></input>
     <label>$LOC_CLOSE</label>
    </button>
   </hbox>
  </vbox>
 </window>"
 gtkdialog3 --program OPTS_DLG > "$HOME/.config/cuesplitter/plugins/flac/preferences"
}

convert_file() {
 flac -"$COMP" -T title="$TITLE" -T artist="$ARTIST" -T album="$ALBUM" -T date="$DATE" -T genre="$GENRE" -T Comment="$COMMENT" -T TRACKNUMBER="$TRACKNUM" "$FNAME"
}
